

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Token &mdash; O365  documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=b86133f3" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=e59714d7" />

  
      <script src="../../_static/jquery.js?v=5d32c60e"></script>
      <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
      <script src="../../_static/documentation_options.js?v=5929fcd5"></script>
      <script src="../../_static/doctools.js?v=9bcbadda"></script>
      <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Utils" href="utils.html" />
    <link rel="prev" title="Query" href="query.html" />
    <link href="../../_static/css/style.css" rel="stylesheet" type="text/css">

</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../index.html">
            
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../overview.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../usage.html">Detailed Usage</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../connection.html">Protocols</a></li>
<li class="toctree-l2"><a class="reference internal" href="../connection.html#resources">Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="../account.html">Account</a></li>
<li class="toctree-l2"><a class="reference internal" href="../account.html#account-class-and-modularity">Account Class and Modularity</a></li>
<li class="toctree-l2"><a class="reference internal" href="../addressbook.html">Address Book</a></li>
<li class="toctree-l2"><a class="reference internal" href="../calendar.html">Calendar</a></li>
<li class="toctree-l2"><a class="reference internal" href="../directory.html">Directory and Users</a></li>
<li class="toctree-l2"><a class="reference internal" href="../excel.html">Excel</a></li>
<li class="toctree-l2"><a class="reference internal" href="../group.html">Group</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mailbox.html">Mailbox</a></li>
<li class="toctree-l2"><a class="reference internal" href="../onedrive.html">OneDrive</a></li>
<li class="toctree-l2"><a class="reference internal" href="../planner.html">Planner</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sharepoint.html">Sharepoint</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tasks.html">Tasks</a></li>
<li class="toctree-l2"><a class="reference internal" href="../teams.html">Teams</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../utils.html">Utils</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="query.html">Query</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Token</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#filesystemtokenbackend">FileSystemTokenBackend</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="utils.html">Utils</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../api.html">O365 API</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">O365</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../usage.html">Detailed Usage</a></li>
          <li class="breadcrumb-item"><a href="../utils.html">Utils</a></li>
      <li class="breadcrumb-item active">Token</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/usage/utils/token.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
        <a href="query.html" class="btn btn-neutral float-left" title="Query" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="utils.html" class="btn btn-neutral float-right" title="Utils" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  </div>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="token">
<h1>Token<a class="headerlink" href="#token" title="Link to this heading"></a></h1>
<p>When initiating the account connection you may wish to store the token for ongoing usage, removing the need to re-authenticate every time. There are a variety of storage mechanisms available which are shown in the detailed api.</p>
<section id="filesystemtokenbackend">
<h2>FileSystemTokenBackend<a class="headerlink" href="#filesystemtokenbackend" title="Link to this heading"></a></h2>
<p>To store the token in your local file system, you can use the <code class="docutils literal notranslate"><span class="pre">FileSystemTokenBackend</span></code>. This takes a path and a file name as parameters.</p>
<p>For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span><span class="p">,</span> <span class="n">FileSystemTokenBackend</span>

<span class="n">token_backend</span> <span class="o">=</span> <span class="n">FileSystemTokenBackend</span><span class="p">(</span><span class="n">token_path</span><span class="o">=</span><span class="n">token_path</span><span class="p">,</span> <span class="n">token_filename</span><span class="o">=</span><span class="n">token_filename</span><span class="p">)</span>

<span class="n">account</span> <span class="o">=</span> <span class="n">Account</span><span class="p">(</span><span class="n">credentials</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;my_client_id&#39;</span><span class="p">,</span> <span class="s1">&#39;my_client_secret&#39;</span><span class="p">),</span> <span class="n">token_backend</span><span class="o">=</span><span class="n">token_backend</span><span class="p">)</span>
</pre></div>
</div>
<p>The methods are similar for the other token backends.</p>
<p>You can also pass in a cryptography manager to the token backend so encrypt the token in the store, and to decrypt on retrieval. The cryptography manager must support the <code class="docutils literal notranslate"><span class="pre">encrypt</span></code> and <code class="docutils literal notranslate"><span class="pre">decrypt</span></code> methods.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span><span class="p">,</span> <span class="n">FileSystemTokenBackend</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">xxx</span><span class="w"> </span><span class="kn">import</span> <span class="n">CryptoManager</span>

<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;my really secret key&quot;</span>
<span class="n">mycryptomanager</span> <span class="o">=</span> <span class="n">CryptoManager</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

<span class="n">token_backend</span> <span class="o">=</span> <span class="n">FileSystemTokenBackend</span><span class="p">(</span><span class="n">token_path</span><span class="o">=</span><span class="n">token_path</span><span class="p">,</span> <span class="n">token_filename</span><span class="o">=</span><span class="n">token_filename</span><span class="p">,</span> <span class="n">cryptography_manager</span><span class="o">=</span><span class="n">mycryptomanager</span><span class="p">)</span>

<span class="n">account</span> <span class="o">=</span> <span class="n">Account</span><span class="p">(</span><span class="n">credentials</span><span class="o">=</span><span class="p">(</span><span class="s1">&#39;my_client_id&#39;</span><span class="p">,</span> <span class="s1">&#39;my_client_secret&#39;</span><span class="p">),</span> <span class="n">token_backend</span><span class="o">=</span><span class="n">token_backend</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="query.html" class="btn btn-neutral float-left" title="Query" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="utils.html" class="btn btn-neutral float-right" title="Utils" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2025, alejcas.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>